const ADD = "counter/ADD"
const REDUCE = "counter/REDUCE"

const initialState = {
  count: 1
}

export default (state = initialState, action) => {
  switch (action.type) {
    case ADD:
      return {
        count: state.count + 1
      }

    case REDUCE:
      return {
        count: state.count - 1
      }

    default:
      return state
  }
}

export const add = () => {
  return dispatch => {
    dispatch({
      type: ADD
    })
  }
}

export const addAsync = () => {
  return dispatch => {
    return setTimeout(() => {
      dispatch({
        type: ADD
      })
    }, 3000)
  }
}

export const reduce = () => {
  return dispatch => {
    dispatch({
      type: REDUCE
    })
  }
}